#ifndef __DOUBLELINKLIST_H_
#define __DOUBLELINKLIST_H_

#include <stdbool.h>

#define ElementType void*

typedef struct DNode
{
    ElementType data; //存储的数据
    struct DNode* prev;//前继节点
    struct DNode* next;//后继节点 
}DNode;

typedef struct DoubleLinkList
{
    struct DNode* head;//头指针，无头结点
    struct DNode* tail;//尾指针，无头结点
    int len;          //有效节点个数
}DList;

//链表节点打印回调函数
typedef void (*PrintCall)(ElementType data);
//销毁链表节点data域回调函数
typedef void (*DataDestroy)(ElementType data);
//节点数据比较回调函数
typedef int (*DataCompare)(ElementType ctx, ElementType data);


//初始化
int DList_Init(DList* list);
//初始化，返回指针
DList* DList_Creat();
//销毁双向链表
void DList_Destroy(DList* list, void (*DataDestroy)(ElementType));
//遍历,自定打印函数
void DList_Travel(DList* list, void (*PrintCall)(ElementType));
//尾插
void DList_InsertTail(DList* list, ElementType element);
//头插
void DList_InsertHead(DList* list, ElementType element);
//尾删
void DList_PopBack(DList* list);
//头删
void DList_PopFront(DList* list);
//按下标插入
DList* DList_InsertByIndex(DList* list, int index, ElementType element);
//按位删除
void DList_RemoveByIndex(DList* list, int index);
//查找第一个值符合的元素
int DList_FindFirstByElement(DList* list, ElementType element, DataCompare dataCompare);
//按值删除
void DList_RemoveByElement(DList* list, ElementType element, DataCompare dataCompare);
//查找下标所对应的值
ElementType DList_FindByIndex(DList* list, int index);
//通过下标设定值
void DList_SetValueByIndex(DList* list, int index, ElementType element);
//更改元素值
void DList_SetValueByElement(DList* list, ElementType oldValue, ElementType newValue, DataCompare dataCompare); 


#endif